<template>
    <div>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" icon="el-icon-plus" size="mini"    :disabled="isButtonDisabled"
                     @click="handleClick"   >定期盘点</el-button>
        </el-col>
      </el-row>
      <el-table
          :data="tableData"
          border
          style="width: 100%">
        <el-table-column
            fixed
            prop="id"
            label="id"
            width="100">
        </el-table-column>
        <el-table-column
            prop="cropName"
            label="作物名称"
            width="100">
        </el-table-column>
        <el-table-column
            prop="cropId"
            label="作物编号"
            width="100">
        </el-table-column>
        <el-table-column
            prop="inventoryUser"
            label="盘点人"
            width="150">
        </el-table-column>
        <el-table-column
            prop="status"
            label="盘点状态"
            width="150">
          <template v-slot="s">
            <span v-if="s.row.status==0">未盘点</span>
            <span v-if="s.row.status==1">已盘点</span>
          </template>
        </el-table-column>
        <el-table-column
            prop="title"
            label="盘点结果"
            width="150">
        </el-table-column>

        <el-table-column
            prop="cropDataSum"
            label="库存数量"
            width="150">
        </el-table-column>
        <el-table-column
            prop="cropRealitySum"
            label="爬电数量"
            width="150">
          <template v-slot="s">
            <el-input-number v-model="s.row.cropRealitySum" @change="handleChange" :min="1" label="描述文字"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <span v-if="scope.row.status==0">
               <el-button
                   size="mini"
                   type="text"
                   icon="el-icon-edit"
                   @click="gopan(scope.row)"
                   v-hasPermi="['system:dict:edit']"
               >去盘点</el-button>
            </span>
            <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="dayin(scope.row)"
                v-hasPermi="['system:dict:edit']"
            >打印盘点单</el-button>
          </template>

        </el-table-column>
      </el-table>
      <el-pagination
          @current-change="gopage"
          :page-size="size"
          layout="total, prev, pager, next"
          :total="total">
      </el-pagination>
    </div>
</template>

<script>
export default {
  name: "DingpanstockView.vue",
  data(){
    return{
      tableData:[],
      size:3,
      total:0,
      current:1,
      isButtonDisabled:false,
    }
  },methods:{
    handleClick() {
      if (!this.isButtonDisabled) { // 如果按钮没有被禁用
        this.isButtonDisabled = true; // 禁用按钮
        // 这里执行你的“定期盘点”逻辑
        this.ding(); // 假设你有一个ding方法来处理点击事件
      }
    },
    dayin(row){
      let params = new URLSearchParams();
      for (let key in row) {
        if (Object.prototype.hasOwnProperty.call(row, key)) {
          params.append(key, row[key]);
        }
      }
      location.href="http://localhost:10010/cropservice/crop/dayin?id="+row.id;
    },
    gopan(row){
      console.log(row);
      this.axios.post("/cropservice/crop/gopan",row).then(res=>{
        if(res.data.code==200){
          this.$message.success(res.data.msg);
          this.list();
        }
      })
    },
    gopage(current){
      this.current=current;
      this.list();
    },
    ding(){
      this.axios.post("/cropservice/crop/pdf/content").then(res=>{
        if(res.data.code==200){
          this.list();
        }else{
          this.$message.error(res.data.msg);
        }
      })
    },
    list(){
      this.axios.post("/cropservice/crop/dingpanlist?current="+this.current+"&size="+this.size).then(res=>{
        if(res.data.code==200){
          this.tableData=res.data.data.list;
          this.total=res.data.data.total;
        }
      })
    },
  },created() {
    this.list();
  },



}
</script>

<style scoped>

</style>